﻿class Main extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            newuser_score: 0,
            surprise: 0,
            shop_dakascore: 0,
            now_smallprobability: 0,
            now_bigprobability: 0

        };
    }














    getdata() {
        let that = this

        获取设置(res => {
            if (res.issuccess == 1) {
                let { newuser_score, surprise, shop_dakascore, now_smallprobability, now_bigprobability } = res.data
                that.setState({ newuser_score, surprise, shop_dakascore, now_smallprobability, now_bigprobability })
            }
        })
    }


    componentDidMount() {
        let sizehtml = [], pricehtml = [], { sizelist, pricelist } = this.state

        this.getdata()


        $('.modal1').hide()
        // testdingcan(res=>{
        // })
        this.setState({ showloading: '' })
        // this.freshlist()

    }

    add() {
        let { newuser_score, surprise, shop_dakascore, now_smallprobability, now_bigprobability } = this.state, that = this, err = '';
        if (isNaN(newuser_score)||newuser_score<0) err = '请输入正确的新用户积分'
        if (isNaN(shop_dakascore)||shop_dakascore<0) err = '请输入正确的打卡积分'
        if (isNaN(surprise)) err = '请输入正确的惊喜礼盒概率'
        if (now_smallprobability == 0) err = '请输入正确的100积分抽奖概率'
        if (now_bigprobability == 0) err = '请输入正确的1000积分抽奖概率'
        if(surprise<0) surprise=1
        if(now_smallprobability<0) now_smallprobability=1
        if(now_bigprobability<0) now_bigprobability=1
        if(surprise>100) surprise=100
        if(now_smallprobability>100) now_smallprobability=100
        if(now_bigprobability>100) now_bigprobability=100

        if (err != '') {
            alert(err)
        } else {

            let data = {newuser_score, surprise, shop_dakascore, now_smallprobability, now_bigprobability}
            编辑设置(data,res=>{
                if(res.issuccess==1){
                    alert('保存成功')

                }
            })
            console.log(data, 'itemm');



            // 添加账号({ shopname: item.name, shopid: item.id, shopnum: select_usernum }, res => {
            //     $('.modal1').hide()
            //     if (res.issuccess == 1) {
            //         that.getdata()

            //     }
            // })

            // 添加账号({desc,name:username,pwd:md5(pwd + Constant.SALT).toUpperCase(),realpwd:pwd},res=>{
            //     $('.modal1').hide() 
            //     if(res.issuccess==1){
            //         that.getdata()
            //     }else{
            //         alert(res.msg)
            //     }
            // })
        }

    }




    inputchange(prop, e) {
        this.setState({ [prop]: e.target.value })
    }
    inputchange1(prop, id, e) {
        let that = this;
        if (prop == "state") {
            that.setState({ showloading: 'ON' })
            Shopsetstate(id, res => {
                if (res.issuccess == 1) {
                    alert("设置成功")
                    that.freshlist()
                } else {
                    that.setState({ showloading: '' })
                    alert(res.msg)
                }
            })
        } else if (prop == "isrecommend") {
            that.setState({ showloading: 'ON' })
            Shopsetrecommend(id, res => {
                if (res.issuccess == 1) {
                    alert("设置成功")
                    that.freshlist()
                } else {
                    that.setState({ showloading: '' })
                    alert(res.msg)
                }
            })
        }

    }


    selectchange(prop, e) {
        this.setState({ [prop]: e.target.value }, () => {
            this.search()
        })
    }



    selectfhchange(e) {
        console.log(e.target.value, 'selectfhchange');
        this.setState({ select_shop: e.target.value })
    }



    jiebang(id) {

        var a = confirm('确定要解绑吗?'), that = this
        if (a) {
            解绑(id, res => {
                if (res.issuccess == 1) {
                    that.getdata()
                }
            })
        }
    }


    render() {
        let { newuser_score, surprise, shop_dakascore, now_smallprobability, now_bigprobability} = this.state;

        return (
            <div className="breadLinebox">
                <div class="alertarea" id='alsucc' >
                </div>


                <Loading hidden={this.state.showloading != 'ON'} />
                     

                <div className='panel-default content_wrap'>
                    <div className="breadLine ">

                    <view className="wrap"> 
           
                        <div className="content">
                            <p className="p1">新用户积分</p>
                            <antd.Input placeholder="请输入新用户积分" allowClear value={newuser_score} onChange={this.inputchange.bind(this, 'newuser_score')} className="input" />
                        </div>

                        <div className="content">
                            <p className="p1">打卡积分</p>
                            <antd.Input placeholder="请输入打卡积分" allowClear value={shop_dakascore} onChange={this.inputchange.bind(this, 'shop_dakascore')} className="input" />
                        </div>

                        <div className="content">
                            <p className="p1">惊喜礼盒概率（1-100整数）</p>
                            <antd.Input placeholder="请输入惊喜礼盒概率" allowClear value={surprise} onChange={this.inputchange.bind(this, 'surprise')} className="input" />
                        </div>

                        <div className="content">
                            <p className="p1">100积分抽奖概率（1-100整数）</p>
                            <antd.Input placeholder="请输入惊喜礼盒概率" allowClear value={now_smallprobability} onChange={this.inputchange.bind(this, 'now_smallprobability')} className="input" />
                        </div>

                        <div className="content">
                            <p className="p1">1000积分抽奖概率（1-100整数）</p>
                            <antd.Input placeholder="请输入惊喜礼盒概率" allowClear value={now_bigprobability} onChange={this.inputchange.bind(this, 'now_bigprobability')} className="input" />
                        </div>

                        <view className="button" onClick={this.add.bind(this)}>保存</view>

                       

                        </view> 



                    </div>


                </div>
            </div>


        )


    }
}

ReactDOM.render(
    <div>
        <TopLine />
        <div id='body'>
            <LeftMenu code='settings' height='settings' />
            <Main />
        </div>
    </div>
    // <Barrage/>
    , $('.container')[0]
)